package com.esri.core.geometry;

import com.github.mikephil.charting.utils.Utils;
import java.io.Serializable;

/* loaded from: classes.dex */
public abstract class Segment extends Geometry implements Serializable {
    private static final long serialVersionUID = 1;
    double a = Utils.DOUBLE_EPSILON;
    double b = Utils.DOUBLE_EPSILON;
    double c = Utils.DOUBLE_EPSILON;
    double d = Utils.DOUBLE_EPSILON;
    double[] e = null;

    /* JADX INFO: Access modifiers changed from: package-private */
    public abstract double a(double d, double d2);

    abstract double a(double d, int i, int i2);

    /* JADX INFO: Access modifiers changed from: package-private */
    public abstract double a(Point2D point2D, boolean z);

    /* JADX INFO: Access modifiers changed from: package-private */
    public abstract int a(SegmentBuffer[] segmentBufferArr);

    abstract Point2D a(double d);

    abstract void a(double d, double d2, SegmentBuffer segmentBuffer);

    abstract void a(double d, Point2D point2D);

    abstract void a(Segment segment);

    abstract boolean a(Point2D point2D, double d, boolean z);

    abstract Segment b(double d, double d2);

    abstract boolean b(double d);

    abstract double c(double d);

    abstract double c(double d, double d2);

    @Override // com.esri.core.geometry.Geometry
    public double calculateArea2D() {
        return Utils.DOUBLE_EPSILON;
    }

    @Override // com.esri.core.geometry.Geometry
    public final int getDimension() {
        return 1;
    }

    public abstract int intersectionWithAxis2D(boolean z, double d, double[] dArr, double[] dArr2);

    abstract boolean isCurve();

    public boolean isEmptyImpl() {
        return false;
    }

    void m() {
    }

    @Override // com.esri.core.geometry.Geometry
    public final void setEmpty() {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Point2D a() {
        return Point2D.construct(this.a, this.b);
    }

    void b(Point2D point2D) {
        point2D.x = this.a;
        point2D.y = this.b;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void c(Point2D point2D) {
        a(0, point2D);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void e(double d, double d2) {
        a(0, Point2D.construct(d, d2));
    }

    Point3D b() {
        return g(0);
    }

    void a(Point3D point3D) {
        a(0, point3D);
    }

    void a(double d, double d2, double d3) {
        a(0, Point3D.construct(d, d2, d3));
    }

    public void queryStart(Point point) {
        a(0, point);
    }

    public void setStart(Point point) {
        b(0, point);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public double a(int i, int i2) {
        return c(0, i, i2);
    }

    int b(int i, int i2) {
        return d(0, i, i2);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i, int i2, double d) {
        a(0, i, i2, d);
    }

    void a(int i, int i2, int i3) {
        a(0, i, i2, i3);
    }

    public double getStartX() {
        return this.a;
    }

    public double getStartY() {
        return this.b;
    }

    public double getEndX() {
        return this.c;
    }

    public double getEndY() {
        return this.d;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Point2D j() {
        return Point2D.construct(this.c, this.d);
    }

    void d(Point2D point2D) {
        point2D.x = this.c;
        point2D.y = this.d;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void e(Point2D point2D) {
        a(1, point2D);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void f(double d, double d2) {
        a(1, Point2D.construct(d, d2));
    }

    Point3D k() {
        return g(1);
    }

    void b(Point3D point3D) {
        a(1, point3D);
    }

    void b(double d, double d2, double d3) {
        a(1, Point3D.construct(d, d2, d3));
    }

    public void queryEnd(Point point) {
        a(1, point);
    }

    public void setEnd(Point point) {
        b(1, point);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public double c(int i, int i2) {
        return c(1, i, i2);
    }

    int d(int i, int i2) {
        return d(1, i, i2);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void b(int i, int i2, double d) {
        a(1, i, i2, d);
    }

    void b(int i, int i2, int i3) {
        a(1, i, i2, i3);
    }

    @Override // com.esri.core.geometry.Geometry
    public final boolean isEmpty() {
        return isEmptyImpl();
    }

    int a(Segment segment, Point2D[] point2DArr, double[] dArr, double[] dArr2, double d) {
        return b(segment, point2DArr, dArr, dArr2, d);
    }

    boolean a(Segment segment, double d) {
        return a(segment, d, false) != 0;
    }

    boolean a(Point2D point2D, double d) {
        return a(point2D, d, false);
    }

    void a(int i) {
        int i2;
        i();
        double[] dArr = this.e;
        if (dArr == null && i > 0) {
            this.e = new double[i * 2];
        } else if (dArr == null || dArr.length >= (i2 = i * 2)) {
        } else {
            double[] dArr2 = new double[i2];
            System.arraycopy(dArr, 0, dArr2, 0, dArr.length);
            this.e = dArr2;
        }
    }

    static void a(double[] dArr, int i, double[] dArr2, int i2, int i3) {
        if (i3 > 0) {
            System.arraycopy(dArr, i, dArr2, i2, i3);
        }
    }

    private Point2D f(int i) {
        Point2D point2D = new Point2D();
        if (i != 0) {
            point2D.setCoords(this.c, this.d);
        } else {
            point2D.setCoords(this.a, this.b);
        }
        return point2D;
    }

    private void a(int i, Point2D point2D) {
        if (i != 0) {
            this.c = point2D.x;
            this.d = point2D.y;
            return;
        }
        this.a = point2D.x;
        this.b = point2D.y;
    }

    private Point3D g(int i) {
        Point3D point3D = new Point3D();
        if (i != 0) {
            point3D.x = this.c;
            point3D.y = this.d;
        } else {
            point3D.x = this.a;
            point3D.y = this.b;
        }
        if (this.m_description.hasZ()) {
            point3D.z = this.e[d(i)];
        } else {
            point3D.z = VertexDescription.getDefaultValue(1);
        }
        return point3D;
    }

    private void a(int i, Point3D point3D) {
        i();
        boolean z = true;
        boolean e = e(1);
        if (e || VertexDescription.isDefaultValue(1, point3D.z)) {
            z = e;
        } else {
            addAttribute(1);
        }
        if (i != 0) {
            this.c = point3D.x;
            this.d = point3D.y;
        } else {
            this.a = point3D.x;
            this.b = point3D.y;
        }
        if (z) {
            this.e[d(i)] = point3D.z;
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void b(int i) {
        i();
        if (isEmptyImpl()) {
            return;
        }
        int a = this.m_description.a(this.m_description.getAttributeIndex(i)) - 2;
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c() - 2;
        if (c > componentCount) {
            int d = d(0);
            int i2 = a + componentCount;
            for (int i3 = i2; i3 < c * 2; i3++) {
                double[] dArr = this.e;
                int i4 = d + i3;
                dArr[i4 - componentCount] = dArr[i4];
            }
            int d2 = d(1) - componentCount;
            while (i2 < c) {
                double[] dArr2 = this.e;
                int i5 = d2 + i2;
                dArr2[i5 - componentCount] = dArr2[i5];
                i2++;
            }
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void c(int i) {
        i();
        int a = this.m_description.a(this.m_description.getAttributeIndex(i)) - 2;
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c() - 2;
        a(c);
        int d = d(0);
        int d2 = d(1);
        int i2 = d2 - componentCount;
        for (int i3 = (c - componentCount) - 1; i3 >= 0; i3--) {
            double[] dArr = this.e;
            dArr[d2 + i3] = dArr[i2 + i3];
        }
        for (int i4 = c - 1; i4 >= a + componentCount; i4--) {
            double[] dArr2 = this.e;
            int i5 = d + i4;
            dArr2[i5] = dArr2[i5 - componentCount];
            int i6 = d2 + i4;
            dArr2[i6] = dArr2[i6 - componentCount];
        }
        double defaultValue = VertexDescription.getDefaultValue(i);
        for (int i7 = 0; i7 < componentCount; i7++) {
            double[] dArr3 = this.e;
            dArr3[d + a + i7] = defaultValue;
            dArr3[d2 + a + i7] = defaultValue;
        }
    }

    private void a(int i, Point point) {
        if (isEmptyImpl()) {
            throw new GeometryException("empty geometry");
        }
        point.a(this.m_description);
        if (point.l()) {
            point.k();
        }
        for (int i2 = 0; i2 < this.m_description.getAttributeCount(); i2++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i2);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i3 = 0; i3 < componentCount; i3++) {
                point.a(_getSemanticsImpl, i3, c(i, _getSemanticsImpl, i3));
            }
        }
    }

    private void b(int i, Point point) {
        i();
        if (point.l()) {
            throw new GeometryException("empty_Geometry");
        }
        VertexDescription description = point.getDescription();
        int attributeCount = description.getAttributeCount();
        for (int i2 = 0; i2 < attributeCount; i2++) {
            int _getSemanticsImpl = description._getSemanticsImpl(i2);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i3 = 0; i3 < componentCount; i3++) {
                a(i, _getSemanticsImpl, i3, point.a(_getSemanticsImpl, i3));
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public double c(int i, int i2, int i3) {
        if (isEmptyImpl()) {
            throw new GeometryException("This operation was performed on an Empty Geometry.");
        }
        if (i2 == 0) {
            return i != 0 ? i3 != 0 ? this.d : this.c : i3 != 0 ? this.b : this.a;
        } else if (i3 >= VertexDescription.getComponentCount(i2)) {
            throw new IndexOutOfBoundsException();
        } else {
            int attributeIndex = this.m_description.getAttributeIndex(i2);
            if (attributeIndex >= 0) {
                if (this.e != null) {
                    a(this.m_description.c() - 2);
                }
                return this.e[((d(i) + this.m_description.a(attributeIndex)) - 2) + i3];
            }
            return VertexDescription.getDefaultValue(i2);
        }
    }

    private int d(int i, int i2, int i3) {
        if (isEmptyImpl()) {
            throw new GeometryException("Empty_Geometry.");
        }
        return (int) c(i, i2, i3);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i, int i2, int i3, double d) {
        i();
        if (i3 >= VertexDescription.getComponentCount(i2)) {
            throw new IndexOutOfBoundsException();
        }
        int attributeIndex = this.m_description.getAttributeIndex(i2);
        if (attributeIndex < 0) {
            addAttribute(i2);
            attributeIndex = this.m_description.getAttributeIndex(i2);
        }
        if (i2 != 0) {
            if (this.e != null) {
                a(this.m_description.c() - 2);
            }
            this.e[((d(i) + this.m_description.a(attributeIndex)) - 2) + i3] = d;
        } else if (i != 0) {
            if (i3 != 0) {
                this.d = d;
            } else {
                this.c = d;
            }
        } else if (i3 != 0) {
            this.b = d;
        } else {
            this.a = d;
        }
    }

    void a(int i, int i2, int i3, int i4) {
        a(i, i2, i3, i4);
    }

    @Override // com.esri.core.geometry.Geometry
    public void copyTo(Geometry geometry) {
        if (geometry.getType() != getType()) {
            throw new IllegalArgumentException();
        }
        Segment segment = (Segment) geometry;
        segment.m_description = this.m_description;
        segment.a(this.m_description.c() - 2);
        a(this.e, 0, segment.e, 0, (this.m_description.c() - 2) * 2);
        segment.a = this.a;
        segment.b = this.b;
        segment.c = this.c;
        segment.d = this.d;
        geometry.i();
        a(segment);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // com.esri.core.geometry.Geometry
    public Envelope1D queryInterval(int i, int i2) {
        Envelope1D envelope1D = new Envelope1D();
        if (isEmptyImpl()) {
            envelope1D.setEmpty();
            return envelope1D;
        }
        envelope1D.vmin = c(0, i, i2);
        envelope1D.vmax = envelope1D.vmin;
        envelope1D.mergeNE(c(1, i, i2));
        return envelope1D;
    }

    void a(double d, Point point) {
        point.a(this.m_description);
        point.a(d(d));
        int attributeCount = this.m_description.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i2 = 0; i2 < componentCount; i2++) {
                point.a(_getSemanticsImpl, i2, a(d, _getSemanticsImpl, i2));
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean b(Segment segment) {
        if (this.m_description == segment.m_description && this.a == segment.a && this.c == segment.c && this.b == segment.b && this.d == segment.d) {
            for (int i = 0; i < (this.m_description.c() - 2) * 2; i++) {
                if (this.e[i] != segment.e[i]) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void l() {
        m();
        double d = this.a;
        this.a = this.c;
        this.c = d;
        double d2 = this.b;
        this.b = this.d;
        this.d = d2;
        int attributeCount = this.m_description.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int semantics = this.m_description.getSemantics(i);
            int componentCount = VertexDescription.getComponentCount(semantics);
            for (int i2 = 0; i2 < componentCount; i2++) {
                double c = c(0, semantics, i2);
                int i3 = i2;
                a(0, semantics, i3, c(1, semantics, i2));
                a(1, semantics, i3, c);
            }
        }
    }

    int a(Segment segment, double d, boolean z) {
        int value = getType().value();
        int value2 = segment.getType().value();
        if (value == 5122) {
            if (value2 == 5122) {
                return Line.a((Line) this, (Line) segment, d, z);
            }
            throw new GeometryException("internal error");
        }
        throw new GeometryException("internal error");
    }

    int b(Segment segment, Point2D[] point2DArr, double[] dArr, double[] dArr2, double d) {
        int value = getType().value();
        int value2 = segment.getType().value();
        if (value == 5122) {
            if (value2 == 5122) {
                return Line.a((Line) this, (Line) segment, point2DArr, dArr, dArr2, d);
            }
            throw new GeometryException("internal error");
        }
        throw new GeometryException("internal error");
    }

    int d(int i) {
        return i * (this.m_description.c() - 2);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Point2D d(double d) {
        Point2D point2D = new Point2D();
        a(d, point2D);
        return point2D;
    }
}
